package com.example.redis.bit.controller;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.example.redis.bit.ActInstanceFactory;
import com.example.redis.bit.domain.IActDomain;
import com.google.common.collect.Lists;
import org.redisson.api.RBitSet;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class RedisBitController {

    @Autowired
    private RedissonClient redissonClient;

    @Autowired
    private RedisConnection redisConnection;

    @GetMapping("/act/init")
    @ResponseBody
    public String initData(){
        ActInstanceFactory.getInstance().initData();
        return "Initializating Data";
    }

    //某一天的用户活跃数
    @GetMapping("/act/{date}")
    @ResponseBody
    public long countUsers(@PathVariable String date){
        return ActInstanceFactory.getInstance().countUsers(date);
    }

    //某一天的redis内存占用
    @GetMapping("/mem/{date}")
    @ResponseBody
    public long mem(@PathVariable String date){
        return ActInstanceFactory.getInstance().mem(date);
    }

    //某一天的某一个用户是否活跃
    @GetMapping("/act/user/{date}/{id}")
    @ResponseBody
    public boolean user(@PathVariable String date, @PathVariable Long id){
        return ActInstanceFactory.getInstance().user(date,id);
    }

    //任意时间段内某一个用户是否活跃
    @GetMapping("/act/user/{dateBegin}/{dateEnd}/{id}")
    @ResponseBody
    public boolean user(@PathVariable String dateBegin, @PathVariable String dateEnd, @PathVariable Long id){
        return ActInstanceFactory.getInstance().user(dateBegin, dateEnd, id);
    }

    //任意时间段内用户活跃数
    @GetMapping("/act/{dateBegin}/{dateEnd}")
    @ResponseBody
    public long act(@PathVariable String dateBegin, @PathVariable String dateEnd){
        return ActInstanceFactory.getInstance().act(dateBegin, dateEnd);
    }
}
